<?php
#============================
#	Filename: soncate.qgmod.php
#	Note	: 根据当前的分类ID得到下一级的分类ID
#	Version : 2.2
#	Author  : qinggan
#	Update  : 2008-5-11
#============================
global $FS,$DB,$prefix,$bi;
$cateid = intval($cateid);
if(!$cateid)

{
	return false;
}
$md5 = md5(TemplateID."_".$cateid."_".$limit);
$cache_file = "data/cache/soncate_".$md5.".php";
$check_status = false;
if($iscache)
{
	$check_status = CheckCache($cache_file);
}
if($check_status)
{
	include_once($cache_file);
	unset($cache_file);
	return $catelist;
}
$sql = "SELECT cat.*,upfi.folder,upfi.thumbfile,upfi.markfile,upfi.filename FROM ".$prefix."category AS cat LEFT JOIN ".$prefix."upfiles AS upfi ON cat.thumb = upfi.id WHERE cat.parentid='".$cateid."' AND cat.status='1' AND cat.language='".LANGUAGE_ID."' ORDER BY cat.taxis ASC,cat.id DESC";
$sql .= " LIMIT 0,".$limit;
$cate_list = $DB->qgGetAll($sql);
if(!$cate_list)
{
	return false;
}
$catelist2 = array();
#[对数组进行排序]
$i = 1;
foreach($cate_list AS $key=>$value)
{
	if($value["thumb2"])
	{
		$sql = "SELECT * FROM ".$prefix."upfiles WHERE id='".$value["thumb2"]."'";
		$rs = $DB->qgGetOne($sql);
		$value["folder2"] = $rs["folder"];
		$value["filename2"] = $rs["filename"];
		$value["markfile2"] = $rs["markfile"];
		$value["thumbfile2"] = $rs["thumbfile"];
	}
	if($value["thumb3"])
	{
		$sql = "SELECT * FROM ".$prefix."upfiles WHERE id='".$value["thumb3"]."'";
		$rs = $DB->qgGetOne($sql);
		$value["folder3"] = $rs["folder"];
		$value["filename3"] = $rs["filename"];
		$value["markfile3"] = $rs["markfile"];
		$value["thumbfile3"] = $rs["thumbfile"];
	}

	$value["catename"] = $value["catename".$bi];
	$value["catename_en"] = $value["catename_en"];
	$value["note"] = $value["note".$bi];
	
	$query = "SELECT * FROM ".$prefix."msg WHERE cateid='".$value["id"]."' ";
	$result=mysql_query($query);
	$number=mysql_num_rows($result);
	
	$sql = "SELECT * FROM ".$prefix."msg WHERE cateid='".$value["id"]."' and additonid = 0  ORDER BY orderdate DESC,id DESC  ";
	$rs = $DB->qgGetOne($sql);
	
	if($rs["id"])
	{
	$value["firstproid"] = $rs["id"];
	}
	else
	{
	$value["firstproid"] = 213;
	}
	
	$value["ischild"] = $number;

	//首项尾项
	if($i==1)
	{
		$value["first"] = true;
	}
	if($i==count($cate_list))
	{
		$value["last"] = true;
	}
	$value["row_index"] = $i;
	$i ++;
	//echo $value["catename"];
	$catelist[] = $value;	
}

$FS->qgWrite($catelist,$cache_file,"catelist");
unset($cache_file);
return $catelist;
?>